<template>
    <div>
        <!--   新增或保存商品弹出层     -->
        <el-dialog
                :title="title"
                :visible.sync="visible"
                width="30%"
        >
            <el-form :model="form" ref="form" label-width="100px" class="demo-ruleForm">
                <el-form-item label="用户名" prop="typename">
                    <el-input v-model="form.typename" suffix-icon="el-icon-user"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
    <el-button @click="visible = false">取 消</el-button>
    <el-button type="primary" @click="saveOrUpdate()">确 定</el-button>
  </span>

        </el-dialog>
        <!--   商品表     -->
        <el-row>
            <el-col :span="6"><el-button type="success" class="addOne" @click="showWin()">新增</el-button></el-col>
            <el-col :span="12"><el-input v-model="typename" placeholder="搜索用户"></el-input></el-col>
            <el-col :span="6"><el-button icon="el-icon-search" @click="load" circle></el-button></el-col>
        </el-row>
        <el-table
                :data="tableData"
                style="width: 100%">
            <el-table-column
                    prop="id"
                    label="类型编号"
            >

            </el-table-column>
            <el-table-column
                    prop="typename"
                    label="商品类型"
            >
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
            >
                <template slot-scope="scope">
                    <el-button @click="showWin(scope.row)" type="text" size="small">编辑</el-button>
                    <el-button type="danger" @click="del(scope.row)" icon="el-icon-delete" circle></el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                background
                @current-change="currentChange"
                layout="prev, pager, next"
                :page-size="pageSize"
                :current-page="currentPage"
                :total="total">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "productstype",
        created() {
            this.loadData()
        },
        data(){
            return{
                visible:false,
                pageSize:5,
                currentPage:1,
                total:1,
                typename:"",
                tableData:[],
                title:"",
                form:[

                ]
            }
        },
        methods:{
            loadData(){
                this.$http.post("/productstype/selectAll",{typename:this.typename,currentPage:this.currentPage,PageSize:this.pageSize}).then(res=>{
                    console.info(res)
                    this.tableData=res.data.list;
                    this.total=res.data.total;
                })
            },
            currentChange(currentPage){
                this.currentPage=currentPage;
                this.loadData()
            },
            load(){
                this.loadData()
            },
            showWin(row){
                this.visible=true;
                if (row){
                    this.form=Object.assign({},row);
                    this.title="修改"
                }else {
                    this.form={}
                    this.title="新增类别"
                }
            },
            saveOrUpdate() {
                this.$http.post("/productstype/saveOrUpdate",this.form).then(res=>{
                    if (res.data.success){
                        this.dialogVisible=false
                        this.loadData()
                    }
                })
            },
            del(row){
                this.$http.post("/productstype/delete",{id:row.id}).then(res=>{
                    if (res.data.success){
                        this.loadData()
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>